package com.zeyuan.rpcclient.netty.basicComp;

import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.util.NettyRuntime;
import io.netty.util.concurrent.EventExecutor;

import java.util.Iterator;
import java.util.concurrent.TimeUnit;

public class TestEventLoop {
    public static void main(String[] args) {
        //1.创建事件循环租
        EventLoopGroup group=new NioEventLoopGroup();
        System.out.println(NettyRuntime.availableProcessors());
        //获取下一个事件循环对象
        group.next();
        Iterator<EventExecutor> iterator = group.iterator();
        while (iterator.hasNext()){
            EventExecutor next = iterator.next();
            //next含有线程池的所有方法
            //执行普通任务
            next.submit(()->{
                try {
                    Thread.sleep(1);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            });
            //执行定时任务
            next.scheduleAtFixedRate(()->{
                System.out.println("aa");
            },1,1, TimeUnit.SECONDS);

        }

    }
}
